import { createRouter, createWebHistory } from 'vue-router';
import HomePage from '../views/Home.vue';
import AboutPage from '../views/About.vue';
import ProjectPage from '../views/Project.vue';
import ServicePage from '../views/Service.vue';
import CompanyPage from '../views/Company.vue';
import NewsPage from '../views/News.vue';
import ContactPage from '../views/Contact.vue';
import PrivacyPolicyPage from '../views/PrivacyPolicy.vue'
import RecruitPage from '../views/Recruit.vue'

const routes = [
  { path: '/', component: HomePage },
  { path: '/about', component: AboutPage },
  { path: '/project', component: ProjectPage },
  { path: '/service', component: ServicePage },
  { path: '/company', component: CompanyPage },
  { path: '/news', component: NewsPage },
  {
    path: '/news/:id',
    name: 'newsDetail',
    component: () => import('../views/NewsDetail.vue'),
    props: (route) => ({
      id: route.params.id, // 通过 params 获取 id
      newsData: route.query.newsData ? JSON.parse(route.query.newsData) : {} // 通过 query 获取 newsData
    })
  },
  
  { path: '/contact', component: ContactPage },
  { path: '/privacy-policy', component: PrivacyPolicyPage },
  { path: '/recruit', component: RecruitPage }
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

export default router;
